package com.gitee.wsl.text.dictomaton

import com.gitee.wsl.collections.list.LinkedList
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue


class DictionaryTest {
    private lateinit var d_words1: List<String>
    private lateinit var d_words2: List<String>
    private lateinit var d_dict: Dictionary

    @BeforeTest
    @Throws(DictionaryBuilderException::class)
    fun initialize() {
        d_words1 = mutableListOf<String>().apply {
            add("al")
            add("alleen")
            add("avonden")
            add("zeemeeuw")
            add("zeker")
            add("zeven")
            add("zoeven")
        }
            

        d_words2 = mutableListOf<String>().apply {
                add("als")
                add("allen")
                add("avond")
                add("zeemeeuwen")
                add("zeer")
                add("zepen")
                add("zoef")
        }

        d_dict = DictionaryBuilder().addAll(d_words1).build()
    }

//    @Test(expected = UnsupportedOperationException::class)
//    fun addTest() {
//        d_dict.add("foo")
//    }
//
//    @Test(expected = UnsupportedOperationException::class)
//    fun addAllTest() {
//        d_dict.addAll(d_words2)
//    }
//
//    @Test(expected = UnsupportedOperationException::class)
//    fun clearTest() {
//        d_dict.clear()
//    }

    @Test
    fun containsTest() {
        for (word in d_words1) assertTrue(d_dict.contains(word))
    }

    @Test
    fun containsAllTest() {
        assertTrue(d_dict.containsAll(d_words1))
        assertFalse(d_dict.containsAll(d_words2))
    }

    @Test
    fun doesNotContainWordsTest() {
        for (word in d_words2) assertTrue(!d_dict.contains(word))
    }

    @Test
    fun emptyTest() {
        val dict = DictionaryBuilder().build()
        assertFalse(dict.contains("foo"))
        assertEquals(0, dict.size)
    }


    val isEmptyTest: Unit
        get() {
            assertFalse(d_dict.isEmpty())
            val dict = DictionaryBuilder().build()
            assertTrue(dict.isEmpty())
        }

    @Test
    fun iterationTest() {
        val listFromIteration = LinkedList<Any>()
        for (seq in d_dict) listFromIteration.add(seq)
        assertContentEquals(d_words1, listFromIteration)
    }

//    @Test(expected = UnsupportedOperationException::class)
//    fun iteratorRemoveTest() {
//        val iter: Iterator<String?> = d_dict!!.iterator()
//        if (iter.hasNext()) iter.remove()
//    }
//
//    @Test(expected = UnsupportedOperationException::class)
//    fun removeTest() {
//        d_dict.remove("foo")
//    }
//
//    @Test(expected = UnsupportedOperationException::class)
//    fun removeAllTest() {
//        d_dict.removeAll(d_words1)
//    }
//
//    @Test(expected = UnsupportedOperationException::class)
//    fun retainAllTest() {
//        d_dict.retainAll(d_words1)
//    }

    @Test
    fun sizeTest() {
        assertEquals(7, d_dict.size)
    }

//    @Test
//    fun toArrayTest() {
//        val check: Array<Any?>? = d_words1.toArray()
//        assertArrayEquals(check, d_dict.toArray())
//
//        val check2 = kotlin.arrayOfNulls<Any>(d_dict.size() + 2)
//        val conv: Array<Any?>? = d_dict.toArray(check2)
//
//        assertTrue(check2 == conv)
//        assertTrue(check2[d_dict.size()] == null)
//    }
}
